package pld.car.dao.impl;

import java.util.List;
import org.hibernate.Query;
import pld.car.bean.SettingsImg;
import pld.car.bean.Settings;
import pld.car.dao.*;

public class SettingsDaoImpl extends BaseDaoImpl implements SettingsDao {

	public SettingsDaoImpl() {
		System.out.println("SettingsDaoImpl init!");
	}

	// 根据输入的SQL，返回对象列表,settings表
	public List<Settings> runSQLForSettings(String sql) {
		Query q = getSession().createQuery(sql);
		List<Settings> list = q.list();
		return list;
	}

	// 修改settings
	public void update(Settings s) {
		getHibernateTemplate().update(s);
	}
	
	//根据settingImgID找到对应的img
	public SettingsImg findImgByID(int id) {
		return (SettingsImg) getHibernateTemplate().get(SettingsImg.class, id);
	}
	
	//删除settingsImg表中的没有imgID的记录
	public void deleteOrphanItems(){
		String sql = "delete from SettingsImg where settings.settingsID=null";
		Query q = getSession().createQuery(sql);
		q.executeUpdate();
	}
}
